package com.cjzuji.rental.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.mapper.OrderMapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.ChangJiuAZJService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order/changjiu")
@Api(tags = "长久爱租机订单类")
//@Component
public class ChangJiuAZJController {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    ChangJiuAZJService changJiuAZJService;
    private static final Logger logger = LoggerFactory.getLogger(ChangJiuAZJController.class);
    @GetMapping("/getAzjInfo")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    @ApiOperation(value = "获取所有订单", notes = "获取所有订单")
    public List<Map<String, Object>> getAzjInfo(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String azjtk = requestHeard.getCjazjtk();
            //System.out.println("azjtk:"+azjtk);
            List<Map<String, Object>> result = changJiuAZJService.getAiZuJiList(azjtk);
            return result;
        } catch (Exception e) {
            logger.error("获取长久爱租机所有订单数据失败！");
            return null;
        }
    }

    //获取租用中的数据
    @PutMapping("/upDateBill")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    @ApiOperation(value = "获取租用中订单", notes = "获取租用中订单")
    public List<Map<String, Object>> upDateBill(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String azjtk = requestHeard.getCjazjtk();
            List<Map<String, Object>> result = changJiuAZJService.upDateBill(azjtk);
            return result;
        }catch (Exception e){
            logger.error("获取长久爱租机租用中订单数据失败！");
            return null;
        }
    }

    //获取逾期订单数据
    @PutMapping("/getOverdue")
    @ApiOperation(value = "获取逾期订单", notes = "获取逾期订单")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    public List<Map<String, Object>> getOverdue(){
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String azjtk = requestHeard.getCjazjtk();
            List<Map<String, Object>> result = changJiuAZJService.getOverdue(azjtk);
            return result;
        } catch (Exception e) {
            logger.error("获取逾期订单数据失败",e);
            return null;
        }
    }
}
